<template>
  <div class="head">
    <div class="title">包干结算报表</div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form
            ref="form"
            style="display: flex;flex-wrap: wrap;margin-top: 24px;justify-content: space-between;"
            :model="form"
            label-width="80px"
          >
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;width: 770px;">
              <el-form-item
                style="margin-left: 0;"
                class="text"
                label="网点"
              >
                <el-select
                  v-model="form.region"
                  :disabled="true"
                  class="input"
                  placeholder="辽宁盘锦公司"
                >
                  <el-option
                    label="辽宁盘锦公司"
                    value="1"
                  />
                </el-select>
              </el-form-item>
              <el-form-item
                class="text"
                label="结算中心"
              >
                <el-select
                  v-model="form.transferCentreId"
                  class="input"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in TransferCenterList"
                    :key="item.id"
                    :label="item.transferCenter"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button
                  type="primary"
                  @click="onSubmit"
                >查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form
            ref="form"
            style="display: flex;justify-content: space-between;flex-wrap: wrap;"
            :model="form"
            label-width="80px"
          >
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;width: 1085px">
              <el-form-item
                class="text"
                style="margin-left: 0;"
                label="查询时间"
                required
              >
                <el-select
                  v-model="form.timeType"
                  class="input"
                  placeholder="请选择"
                >
                  <el-option
                    label="发件日期"
                    value="1"
                  />
                  <el-option
                    label="结算日期"
                    value="2"
                  />
                </el-select>
              </el-form-item>
              <div>
                <el-select
                  v-model="value1"
                  style="width: 156px;"
                  class="input"
                  placeholder="请选择"
                  @change="changeType"
                >
                  <el-option
                    label="包干费日预收"
                    value="1"
                  />
                  <el-option
                    label="包干费日调整"
                    value="2"
                  />
                  <el-option
                    label="包干费月调整"
                    value="3"
                  />
                  <el-option
                    label="日回冲"
                    value="4"
                  />
                </el-select>
                <el-date-picker
                  v-model="value"
                  type="daterange"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  style="width: 500px;margin-left:12px"
                  @change="changeTime"
                />
              </div>
            </div>
            <div>
              <el-form-item>
                <el-button @click="onSubmit"><i class="el-icon-upload2" />导出</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <el-table
          v-loading="loading"
          v-if="value1 === '1' || value1 === '2' || value1 === ''"
          :data="tableData"
          border
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column
            type="index"
            :index="table_index"
            width="50"
            align="center"
          />
          <el-table-column
            prop="name"
            label="发件日期"
            width="180"
            align="center"
          />
          <el-table-column
            prop="address"
            label="结算日期"
            align="center"
          />
          <el-table-column
            prop="networkNameId"
            label="网点编码"
            align="center"
          />
          <el-table-column
            prop="networkName.networkName"
            label="网点名称"
            align="center"
          />
          <el-table-column
            prop="hqTransferCentre.transferCode"
            width="160"
            align="center"
            label="结算中心编码(总部收)"
          />
          <el-table-column
            prop="hqTransferCentre.transferCenter"
            width="160"
            label="结算中心名称(总部收)"
            align="center"
          />
          <el-table-column
            align="center"
            label="日结算"
          >
            <el-table-column
              prop="daySettleAmount"
              width="110"
              label="单件结算金额"
              align="center"
            />
            <el-table-column
              prop="preRefundAmount"
              width="150"
              label="包干预收已返还金额"
              align="center"
            />
            <el-table-column
              v-if="value1 === '2'"
              prop="actualRefundAmount"
              width="150"
              label="包干实际应返金额"
              align="center"
            />
            <el-table-column
              v-if="value1 === '2'"
              prop="actualAdjustAmount"
              width="150"
              label="包干返利调整金额"
              align="center"
            />
          </el-table-column>

          <el-table-column
            align="center"
            label="日追溯"
          >
            <el-table-column
              prop="dayAscendSettleAmount"
              width="110"
              label="单件结算金额"
              align="center"
            />
            <el-table-column
              prop="dayAscendPreRefundAmount"
              width="150"
              label="包干预收已返还金额"
              align="center"
            />
            <el-table-column
              v-if="value1 === '2'"
              prop="dayActualRefundAmount"
              width="150"
              label="包干实际应返金额"
              align="center"
            />
            <el-table-column
              v-if="value1 === '2'"
              prop="dayActualAdjustAmount"
              width="150"
              label="包干返利调整金额"
              align="center"
            />
          </el-table-column>
          <el-table-column
            v-if="value1 === '1' || value1 === '2'"
            prop="underBillAmount"
            align="center"
            label="下账金额"
          />
        </el-table>
        <el-table
          v-loading="loading"
          v-if="value1 === '3'"
          :key="Math.random()"
          :data="tableData"
          border
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column
            type="index"
            :index="table_index"
            width="50"
            align="center"
          />
          <el-table-column
            prop="name"
            label="发件日期"
            width="180"
            align="center"
          />
          <el-table-column
            prop="collectMonth"
            label="结算日期"
            align="center"
          />
          <el-table-column
            prop="networkNameId"
            label="网点编码"
            align="center"
          />
          <el-table-column
            prop="networkName.networkName"
            label="网点名称"
            align="center"
          />
          <el-table-column
            prop="hqTransferCentre.transferCode"
            width="160"
            align="center"
            label="结算中心编码(总部收)"
          />
          <el-table-column
            prop="hqTransferCentre.transferCenter"
            width="160"
            label="结算中心名称(总部收)"
            align="center"
          />
          <el-table-column
            prop="baoGanNum"
            label="包干基数"
            align="center"
          />
          <el-table-column
            prop="baoGanExamine"
            label="包干考核"
            align="center"
          />
          <el-table-column
            prop="examineNum"
            label="考核基数"
            align="center"
          />
          <el-table-column
            prop="examineOnLine"
            label="考核上线"
            align="center"
          />
          <el-table-column
            prop="bigPackageNum"
            label="大包数量"
            align="center"
          />
          <el-table-column
            prop="dayAvgSentNum"
            width="100"
            label="日均发件量"
            align="center"
          />
          <el-table-column
            prop="dayAvgWeight"
            width="110"
            label="日均发件重量"
            align="center"
          />
          <el-table-column
            prop="bigPackageSettleAmount"
            width="110"
            label="大包结算金额"
            align="center"
          />
          <el-table-column
            prop="bigPackageSettleWeight"
            width="110"
            label="大包结算重量"
            align="center"
          />
          <el-table-column
            prop="singletonTicket"
            label="单件票数"
            align="center"
          />
          <el-table-column
            prop="singletonSettleAmount"
            width="110"
            label="单件结算金额"
            align="center"
          />
          <el-table-column
            prop="singletonSettleWeight"
            width="110"
            label="单件结算重量"
            align="center"
          />
          <el-table-column
            prop="systemTotalAmount"
            width="100"
            label="系统总金额"
            align="center"
          />
          <el-table-column
            prop="preBaoGanReturnAmount"
            width="180"
            label="原包干已返还奖金额合计"
            align="center"
          />
          <el-table-column
            prop="monthBaoGanReturnAmount"
            width="140"
            label="月包干应返还金额"
            align="center"
          />
          <el-table-column
            prop="monthBaoGanAdjustAmount"
            width="150"
            label="月包干返还调整金额"
            align="center"
          />
        </el-table>
        <el-table
          v-loading="loading"
          v-if="value1 === '4'"
          :key="Math.random()"
          :data="tableData"
          border
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column
            type="index"
            :index="table_index"
            width="50"
            align="center"
          />
          <el-table-column
            prop="collectDate"
            label="发件日期"
            width="180"
            align="center"
          />
          <el-table-column
            prop="address"
            label="结算日期"
            align="center"
          />
          <el-table-column
            prop="address"
            label="原结算日期"
            align="center"
          />
          <el-table-column
            prop="networkNameId"
            label="网点编码"
            align="center"
          />
          <el-table-column
            prop="networkName.networkName"
            label="网点名称"
            align="center"
          />
          <el-table-column
            prop="hqTransferCentre.transferCode"
            align="center"
            label="结算中心编码(总部收)"
          />
          <el-table-column
            prop="hqTransferCentre.transferCenter"
            label="结算中心名称(总部收)"
            align="center"
          />
          <el-table-column
            prop="preSettleAmount"
            label="原结算金额"
            align="center"
          />
          <el-table-column
            prop="backwashAmount"
            label="回冲金额"
            align="center"
          />

        </el-table>
        <div style="display: flex;justify-content: space-between;margin-top: 51px;">
          <div class="title2" />
          <div
            class="block"
            style="display: flex; justify-content: flex-end"
          >
            <el-pagination
              background
              :current-page="current"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="10"
              layout="total, prev, pager, next"
              :total="+total"
              prev-text="上一页"
              next-text="下一页"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import { TransferCenterApi, LieuDayAdvanceApi, LieuDayAdvanceApi1, LieuDayAdvanceApi2, LieuDayAdvanceApi3 } from '@/api/HqFinancePanel'

export default {

  components: {},
  data() {
    return {
      loading: false,
      value: '',
      value1: '1',
      form: {
        endTime: '',
        networkNameId: '1',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        startTime: '',
        timeType: '',
        transferCentreId: ''
      },
      tableData: [],
      current: 0, // 页数
      pages: 0, // 条数
      total: 0, // 总数
      TransferCenterList: []// 结算中心列表
    }
  },

  computed: {},

  created() {
    this.TransferCenter()
  },

  methods: {
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val
      this.onSubmit()
    },
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val
      this.onSubmit()
    },
    // 序号
    table_index(index) {
      return (this.form.pageDate.pageNum - 1) * this.form.pageDate.pageSize + index + 1
    },
    // 选择时间
    changeTime() {
      if (this.value != null) {
        this.form.startTime = this.value[0]
        this.form.endTime = this.value[1]
      }
    },
    // 重置
    khClear() {
      Object.keys(this.form).forEach((key) => {
        if (key !== 'pageDate' && key !== 'networkNameId') {
          this.form[key] = ''
        }
      })
      this.tableData = []
      this.value = ''
      this.value1 = '1'
      this.total = 0
      this.current = 0
      this.pages = 0
    },
    // 结算中心
    async TransferCenter() {
      const res = await TransferCenterApi()
      this.TransferCenterList = res.data
      console.log(res)
    },
    table(res) {
      this.tableData = res.data.data
      this.total = res.data.total
      this.current = res.data.current
      this.pages = res.data.pages
    },
    // 查询
    async onSubmit() {
      let res = null
      if (this.value1 === '1') {
        res = await LieuDayAdvanceApi(this.form)
      } else if (this.value1 === '2') {
        res = await LieuDayAdvanceApi1(this.form)
      } else if (this.value1 === '3') {
        res = await LieuDayAdvanceApi2(this.form)
      } else if (this.value1 === '4') {
        res = await LieuDayAdvanceApi3(this.form)
      }
      this.loading = true
      if (res.code == 200) {
        this.table(res)
      }
      this.loading = false
    },
    changeType() {
      this.tableData = []
    }
  }
}

</script>
<style
  scoped
  lang="scss"
>
.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}

.line {
  height: 1px;
  background: #D8D8D8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {

  // display: flex;
  // justify-content: space-between;
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    .input {
      width: 286px;
      height: 36px;
      background: #FFFFFF;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #FFFFFF;
      border: 1px solid #B4B4B4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
